home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Src / lconsole / mtas.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  3.8 KB  |  182 lines

  1. /* mta.c: mta functions */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Src/lconsole/RCS/mtas.c,v 6.0 1991/12/18 20:27:16 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Src/lconsole/RCS/mtas.c,v 6.0 1991/12/18 20:27:16 jpo Rel $
  9.  *
  10.  * $Log: mtas.c,v $
  11.  * Revision 6.0  1991/12/18  20:27:16  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16. #include "lconsole.h"
  17. #include "qmgr.h"
  18. #include "qmgr-int.h"
  19. #include <isode/cmd_srch.h>
  20. #ifdef  BSD42
  21. #include <sys/ioctl.h>
  22. #endif
  23.  
  24. #define plural(n,s)    ((n) == 1 ? "" : (s))
  25.  
  26. static char *mtatolist;
  27.  
  28. static void display_mta_info (mip)
  29. MtaInfo *mip;
  30. {
  31.     printf ("%*sMTA %s on channel %s\n",
  32.         indent * 2, "",
  33.         mip -> mta, mip -> channel);
  34.     indent ++;
  35.     printf ("%*s%s message%s, ", indent * 2, "",
  36.         datasize (mip -> numberMessages, ""),
  37.         plural(mip -> numberMessages,"s"));
  38.     printf ("%s delivery report%s, ",
  39.         datasize (mip->numberReports, ""),
  40.         plural(mip->numberReports,"s"));
  41.     printf ("%s data\n",
  42.         datasize (mip -> volumeMessages, ""));
  43.     if (mip -> active)
  44.         printf ("%*sMTA currently being delivered\n",
  45.             indent * 2, "");
  46.     display_status (mip -> status);
  47.  
  48.     if (mip -> oldestMessage && (mip -> numberReports > 0 ||
  49.                      mip -> numberMessages > 0))
  50.         printf ("%*sOldest message is %s", indent * 2, "",
  51.             ctime (&mip -> oldestMessage));
  52.     indent --;
  53. }
  54.  
  55. static void display_all_mtas (mtas)
  56. MtaInfo *mtas;
  57. {
  58.     MtaInfo *mip;
  59.     int width, w;
  60.     int count;
  61.     char **cpp;
  62.  
  63.     for (count = 0, mip = mtas; mip; mip = mip -> next)
  64.         count ++;
  65.     cpp = (char **) smalloc (count * sizeof (char *));
  66.  
  67.     for (width = count = 0, mip = mtas; mip; mip = mip -> next) {
  68.         char buf[BUFSIZ];
  69.         char c[2];
  70.  
  71.         c[1] = NULL;
  72.         c[0] = ':';
  73.         if (mip -> active)
  74.             c[0] = '*';
  75.         if (mip -> status -> enabled == 0)
  76.             c[0] = '!';
  77.  
  78.         if (mip -> numberReports != 0)
  79.             (void) sprintf (buf, "%s%s%d+%d",
  80.                     mip -> mta, c,
  81.                     mip -> numberMessages,
  82.                     mip -> numberReports);
  83.         else if (mip -> numberMessages != 0)
  84.             (void) sprintf (buf, "%s%s%d",
  85.                     mip -> mta, c,
  86.                     mip -> numberMessages);
  87.         else    (void) sprintf (buf, "%s%s", mip -> mta,
  88.                     c[0] == ':' ? "" : c);
  89.         if ((w = strlen (buf)) > width)
  90.             width = w;
  91.         cpp[count++] = strdup (buf);
  92.     }
  93.     w = ncols (stdout) / (width+1);
  94.     for (count = 0, mip = mtas; mip; mip = mip -> next) {
  95.         printf ("%-*s%s", width, cpp[count],
  96.             (count + 1) % w == 0 ? "\n" : " ");
  97.         free (cpp[count++]);
  98.     }
  99.     if (count % w != 0)
  100.         putchar ('\n');
  101.     free ((char *)cpp);
  102.  
  103. }
  104.  
  105.  
  106. /* ARGSUSED */
  107. int mta_update(mta, id)
  108. MtaInfo *mta;
  109. int id;
  110. {
  111.     int found = 0;
  112.     MtaInfo *mip;
  113.     char *cp;
  114.  
  115.     if (mta == NULL)
  116.         advise (NULLCP, "No MTA's found");
  117.     else if (mtatolist) {
  118.         found = 0;
  119.         if ((cp = re_comp (mtatolist)) != NULLCP) {
  120.             advise (NULLCP, "Expression %s: %s",
  121.                 mtatolist, cp);
  122.             free_MtaInfo (mta);
  123.             return OK;
  124.         }
  125.         for (mip = mta; mip; mip = mip -> next) {
  126.             if (re_exec (mip -> mta) == 1) {
  127.                 display_mta_info (mip);
  128.                 found ++;
  129.             }
  130.         }
  131.         if (found == 0)
  132.             advise (NULLCP, "MTA %s not found", mtatolist);
  133.     }
  134.     else if (mta -> next == NULL)
  135.         display_mta_info (mta);
  136.     else
  137.         display_all_mtas (mta);
  138.  
  139.     free_MtaInfo (mta);
  140.     return OK;
  141. }
  142.  
  143. int f_mta (vec)
  144. char **vec;
  145. {
  146.     char errbuf[BUFSIZ];
  147.     int pid;
  148.     char buffer[BUFSIZ];
  149.     char *av[NVARGS];
  150.  
  151.     if (*++vec == NULLCP) {
  152.         if (getline ("Channel to list MTA's on: ", buffer) == NOTOK ||
  153.             str2vec (buffer, av) < 1)
  154.             return OK;
  155.         vec[1] = NULLCP;
  156.     }
  157.     else av[0] = *vec;
  158.     av[0] = fullchanname (av[0]);
  159.     if (av[0] == NULLCP)
  160.         return NOTOK;
  161.  
  162.     if (*++vec == NULLCP) {
  163.         mtatolist = NULLCP;
  164.     }
  165.     else {
  166.         mtatolist = *vec;
  167.     }
  168.     
  169.     if (initiate_op (console_fd, operation_Qmgr_mtaread,
  170.              av, &pid, mta_update, errbuf) == NOTOK) {
  171.         advise (NULLCP, "status operation failed: %s", errbuf);
  172.         return NOTOK;
  173.     }
  174.  
  175.     if (result_op (console_fd, &pid, errbuf) == NOTOK) {
  176.         advise (NULLCP, "result_op: %s", errbuf);
  177.         return NOTOK;
  178.     }
  179.     
  180.     return OK;
  181. }
  182.